package jxcmanager.jxc;

import jxcmanager.jxc.ecxeptions.ParamsException;
import jxcmanager.jxc.model.RespBean;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;



/**
 * 系统引入了全局异常机制后，在service层可以不用try catch ，系统会自动引用全局异常处理
 */
@ControllerAdvice
public class GlobalExceptionHandler {


    /**
     * 没有权限，权限认证失败异常处理，跳转到403页面
     * @param e
     * @return
     */
    @ExceptionHandler(AccessDeniedException.class)
    public String accessDeniedException(AccessDeniedException e){
        return "403";
    }

    @ExceptionHandler(ParamsException.class)
    @ResponseBody
    public RespBean paramsExceptionHandler(ParamsException e){
        return RespBean.error(e.getMsg());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public RespBean exceptionHandler(Exception e){
        return RespBean.error(e.getMessage());
    }
}
